package org.metasketch.graphics.registry;

import java.util.HashMap;
import java.util.Map;

public class GraphicsRegistry {

	Map<String, Class> graphicsPerType = new HashMap<String, Class>();

	public void register(String type, Class graphic) {
		if (IGraphic.class.isAssignableFrom(graphic))
			graphicsPerType.put(type, graphic);
	}

	public IGraphic get(String name) throws Throwable {
		Class type = graphicsPerType.get(name);

		if (type == null)
			return null;

		IGraphic node = (IGraphic) type.newInstance();
		return node;
	}

}
